package com.rdzn.mall.center.service.impl;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.rdzn.mall.center.entity.PmsProduct;
import com.rdzn.mall.center.entity.SmsHomeRecommendProduct;
import com.rdzn.mall.center.mapper.SmsHomeRecommendProductMapper;
import com.rdzn.mall.center.service.IPmsProductService;
import com.rdzn.mall.center.service.ISmsHomeRecommendProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @Description: sms_home_recommend_product
 * @Author: jeecg-boot
 * @Date:   2020-08-27
 * @Version: V1.0
 */

@Service
public class SmsHomeRecommendProductServiceImpl extends ServiceImpl<SmsHomeRecommendProductMapper, SmsHomeRecommendProduct> implements ISmsHomeRecommendProductService {

    @Autowired
    private IPmsProductService productService;

    @Override
    public List<PmsProduct> getList() {
        List<SmsHomeRecommendProduct> list = list(new LambdaQueryWrapper<SmsHomeRecommendProduct>().eq(SmsHomeRecommendProduct::getRecommendStatus, 1).orderByDesc(SmsHomeRecommendProduct::getSort));
        if (CollectionUtils.isNotEmpty(list)){
            List<Integer> ids = list.stream().map(SmsHomeRecommendProduct::getProductId).collect(Collectors.toList());
            return productService.getByIds(ids);
        }
        return null;
    }

}
